<?php
	DEFINE('H1', 'Factorial Calculator');
	DEFINE('TITLE','Factorial Calculator');
	require('includes/header.php');
?>	
	<h2><?PHP echo H1 ?></h2>
<?php
function factorial($n)
{if ($n == 1)
	return 1;
	return( $n*factorial($n-1));
	}
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>" >
Enter Number:
<input type="text" name="num" value="<?php if (isset($_POST['num'])) echo $_POST['num']; ?>" />
<br />
<input type="submit" name="submit" value="Calculate Factorial" />
</form>
<br />
<?php 

if(isset($_POST['submit']))
{
$n = $_POST['num'];
$ans = factorial($n);
echo "$n Factorial is $ans";
}
?>
<?php
	require('includes/footer.php');
?>